<template>
  <div class="container">
    <div class="header">
      <img :src="imgUrls + '/file/' + userInfo.avatar">
      <div class="info">
        <div class="name">{{ userInfo.nickname }}</div>
        <div class="inte">已累计{{ userInfo.integral }}分</div>
      </div>
    </div>
    <div class="center">
      <div class="log">
        <div class="day" v-for="(item, index) in integralList" :key="index">
          <div>
            <div class="day1">{{ item.day }}</div>
            <img class="simg" src="https://tc.iimx.cn/picgo/202212031745480.png" />
            <div class="day2">{{ item.sign_num }}</div>
          </div>
        </div>
      </div>
      <van-button class="start" round type="danger" @click="startIntegral">立即签到</van-button>
    </div>
    <div class="button">
      <div class="inte-log">
        <div class="title">积分记录</div>
        <div class="inteDay">
          已签到
          <div class="warp" >
            {{  integralLog.length }}
          </div>
          天
        </div>
        <div class="list">
          <div class="item" v-for="(item, index) in integralLog" :key="index">
            <div class="left">
              <div class="name">{{ item.title }}</div>
              <div class="time">{{ item.addTime }}</div>
            </div>
            <div class="right">
              <div class="num">{{ item.number }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { integralConfig, userIntegralConfig, startIntegral } from '@/api/integral.js'
import { getUserInfo } from '@/api/login.js'
export default {
  data() {
    return {
      integralList: [],
      isShow_o: true,
      isShow_c: false,
      integralLog: [],
      userInfo: {
        avatar: '',
        nickname: '',
        integral: 0
      }, //用户信息,
      imgUrls: this.$baseApi,
      warp:0
    }
  },
  created() {
    this.getConfig()
    this.userIntegral()
    this.getUserInfo()
  },
  methods: {
    // 获取签到配置
    getConfig() {
      integralConfig().then(res => {
        this.integralList = res.data
        // console.log(this.integralList);
      })
    },
    //打开菜单栏
    openValue() {
      this.isShow_o = !this.isShow_o
      this.isShow_c = !this.isShow_c
    },
    // 获取用户签到记录
    userIntegral() {
      userIntegralConfig().then(res => {
        this.integralLog = res.data
        console.log(this.integralLog);
      })
    },
    // 开始签到
    startIntegral() {
      startIntegral().then(res => {
        location.reload()
      })
    },
    getUserInfo() {
      getUserInfo().then(res => {
        this.userInfo.avatar = res.data.avatar
        this.userInfo.nickname = res.data.nickname
        this.userInfo.integral = res.data.integral
        // console.log(res.data);
      })
    }
  }
}

</script>
<style lang="scss">
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.container {
  width: 100%;
  height: 100%;
  background: #f5f5f5;
  position: absolute;

  .header {
    width: 100%;
    height: 180px;
    background-color: red;

    img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      margin: 30px 0 0 30px;
      border: 2px solid #fff;
      float: left;
    }

    .info {
      float: left;
      margin-left: 20px;

      .name {
        font-size: 18px;
        color: #fff;
        margin-top: 30px;
      }

      .inte {
        font-size: 14px;
        color: #fff;
        margin-top: 10px;
        text-align: center;
        width: 90px;
        height: 20px;
        background-color: orange;
        border-radius: 5px;
      }
    }
  }

  .center {
    position: relative;
    top: -80px;
    margin: 0 auto;
    width: 90%;
    height: auto;
    background-color: rgb(237, 231, 231);
    margin-top: 10px;
    border-radius: 10px;

    .log {
      display: flex;
      justify-content: space-around;

      .day {
        width: 80px;
        text-align: center;
        margin-top: 20px;
        margin-bottom: 20px;

        .day1 {
          font-size: 13px;
          color: rgb(81, 80, 80);
          margin-bottom: 10px;
        }

        .day2 {
          font-size: 13px;
          color: rgb(81, 80, 80);
          margin-top: 10px;

        }

        .simg {
          width: 30px;
          height: 30px;
          margin: 0 auto;
          display: block;
        }
      }
    }

    .start {
      width: 50%;
      margin-left: 24%;
      margin-bottom: 20px;
    }
  }

  .button {
    margin: 0 auto;
    margin-top: -60px;
    position: relative;
    width: 90%;
    height: auto;
    background-color: #fff;
    border-radius: 10px;
    padding-bottom: 20px;

    .inte-log {
      text-align: center;
      width: 90%;
      height: auto;

      .title {
        font-size: 30px;
        color: rgb(81, 80, 80);
        margin: 0 auto;
      }

      .inteDay {
        font-size: 14px;
        color: rgb(81, 80, 80);
        margin: 0 auto;
        margin-top: 10px;
      }

      .warp {
        display: inline-block;
        margin: 0 auto;
        width: 0.8rem;
        height: 1.16rem;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        color: #fff;
        font-size: 0.72rem;
        text-align: center;
        line-height: 1.16rem;
        margin-right: 2px;
        background-image: url('https://tc.iimx.cn/picgo/202212031812711.png')
      }

      .list {
        margin-top: 10px;

        .item {
          display: flex;
          justify-content: space-between;
          margin-top: 10px;
          margin-left: 5px;

          .left {
            margin-left: 5px;

            .name {
              font-size: 14px;
              color: rgb(81, 80, 80);
            }

            .time {
              font-size: 12px;
              color: rgb(81, 80, 80);
              margin-left: 5px;
            }
          }

          .right {
            .num {
              margin-top: 10px;
              font-size: 14px;
              color: rgb(81, 80, 80);
            }
          }
        }
      }
    }
  }

}
</style>
